<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">

            <h:form id="cidadaoForm" enctype="multipart/form-data">
                <br/>
                <h3 class="title">Atualizando Proprietário</h3>
                <p:growl id="messages" showDetail="true" autoUpdate="true" /> 
                <p:panel id="personPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix both ">
                    <h4 class="title">Dados Gerais</h4>

                    
                    <p:outputLabel id="personOutputLabel" value="Pessoa: " styleClass="grid_3" style="top: 6px" />
                    <div class="grid_8">
                        <p:selectOneRadio id="personRadioButton" value="#{managerProprietario.editarProprietario.tipoDocumento}" >
                            <f:selectItems value="#{managerProprietario.tipoDocumentoList()}" />
                            <p:ajax event="change" update=":cidadaoForm:personPanel" />
                        </p:selectOneRadio>
                    </div>
                    <div class="clear" />

                    <p:outputLabel id="tipoDocumentoLabel" for="tipoDocumentoInput"
                                   value="#{managerProprietario.renderInputsCpf  ? 'CPF' : 'CNPJ'}:" 
                                   styleClass="grid_3"/>
                    <p:inputMask id="tipoDocumentoInput" 
                                 value="#{managerProprietario.renderInputsCpf ? 
                                          managerProprietario.editarProprietario.cpf : managerProprietario.editarProprietario.cnpj}"
                                          mask="#{managerProprietario.renderInputsCpf ? '999.999.999-99' : '99.999.999/9999-99'}"
                                 styleClass="grid_8" > 
                    </p:inputMask>

                    <p:outputLabel value="RG:" styleClass="grid_3" for="rgInputText" 
                                   rendered="#{managerProprietario.renderInputsCpf}" />
                    <p:inputText id="rgInputText" styleClass="grid_8" 
                                 value="#{managerProprietario.editarProprietario.rg}" 
                                 rendered="#{managerProprietario.renderInputsCpf}" />
                    <div class="clear" />

                    <p:outputLabel value="Nome: " styleClass="grid_3" for="nomeInputText" 
                                   rendered="#{managerProprietario.renderInputsCpf}"/>
                    <p:inputText id="nomeInputText" styleClass="grid_20 ajustInput" 
                                 value="#{managerProprietario.editarProprietario.nome}" 
                                 rendered="#{managerProprietario.renderInputsCpf}" />

                    <p:outputLabel value="Profissão: " styleClass="grid_3" for="profissaoInputText" 
                                   rendered="#{managerProprietario.renderInputsCpf}" />
                    <p:inputText id="profissaoInputText" styleClass="grid_8" 
                                 value="#{managerProprietario.editarProprietario.profissao}" 
                                 rendered="#{managerProprietario.renderInputsCpf}" />

                    <p:outputLabel value="Local de Trabalho:" styleClass="grid_3 localTrabalhoLabel" 
                                   for="localTrabalhoInputText" 
                                   rendered="#{managerProprietario.renderInputsCpf}" />
                    <p:inputText id="localTrabalhoInputText" styleClass="grid_8" 
                                 value="#{managerProprietario.editarProprietario.localTrabalho}" 
                                 rendered="#{managerProprietario.renderInputsCpf}" />

                    <p:outputLabel value="Data Nasc.:" styleClass="grid_3"
                                   for="dateNascCalendar" style="margin-left: 11px;"
                                   rendered="#{managerProprietario.renderInputsCpf}" />
                    <p:calendar id="dateNascCalendar" value="#{managerProprietario.editarProprietario.dataNasc}" 
                                showOn="button"
                                styleClass="grid_8" rendered="#{managerProprietario.renderInputsCpf}" />
                    <div class="clear"/>

                    <p:outputLabel value="Nome Fantasia:" styleClass="grid_3"
                                   for="nameFantasyInputText" rendered="#{!managerProprietario.renderInputsCpf}" />
                    <p:inputText id="nameFantasyInputText" styleClass="grid_20 ajustInput"
                                 value="#{managerProprietario.editarProprietario.nomeFantasia}" 
                                 rendered="#{!managerProprietario.renderInputsCpf}" />
                    <br/>

                    <h4 class="title">Endereço</h4>
                    <div class="clear" />
                    <p:panel id="addressPanel"
                             style="background: none; border: none; margin-left: -15px; margin-top: -25px;" 
                             styleClass="container_24 clearfix both ">

                        <p:outputLabel value="CEP:" styleClass="grid_3" for="cepInputMask" />
                        <p:inputMask  id="cepInputMask" styleClass="grid_4" mask="99.999-999"
                                      value="#{managerProprietario.editarProprietario.endereco.cep}" > 
                            <p:ajax event="blur" update=":cidadaoForm:addressPanel"  
                                    listener="#{managerProprietario.existeEndereco()}" />
                        </p:inputMask>
                        <div class="clear"/>

                        <p:outputLabel value="Cod. Logra.:" styleClass="grid_3" 
                                       for="codLogradouroInputText" />
                        <p:inputText id="codLogradouroInputText" styleClass="grid_4" 
                                     value="#{managerProprietario.editarProprietario.endereco.codLogradouro}" />

                        <p:outputLabel value="Logradouro:" styleClass="grid_3 alpha" for="patioInputText" />
                        <p:inputText id="patioInputText" styleClass="grid_13" 
                                     value="#{managerProprietario.editarProprietario.endereco.logradouro}" />

                        <p:outputLabel value="Cod. Bairro:" styleClass="grid_3" for="codBairroInputText" />
                        <p:inputText id="codBairroInputText" styleClass="grid_4" 
                                     value="#{managerProprietario.editarProprietario.endereco.codBairro}" />

                        <p:outputLabel value="Bairro: " styleClass="grid_3 alpha" for="bairroInputText" />
                        <p:inputText id="bairroInputText" styleClass="grid_13" 
                                     value="#{managerProprietario.editarProprietario.endereco.bairro}" />

                        <p:outputLabel value="Estado: " styleClass="grid_3" for="estadoInputText" />
                        <p:inputText id="estadoInputText" styleClass="grid_4"
                                     value="#{managerProprietario.editarProprietario.endereco.uf}" />

                        <p:outputLabel value="Município: " styleClass="grid_3 alpha" for="municipioInputText" />
                        <p:inputText id="municipioInputText" styleClass="grid_13"
                                     value="#{managerProprietario.editarProprietario.endereco.municipio}" />

                        <p:outputLabel value="Número: " styleClass="grid_3" for="numInputText" />
                        <p:inputText id="numInputText" styleClass="grid_4"
                                     value="#{managerProprietario.editarProprietario.endereco.numero}" />

                        <p:outputLabel value="Complemento: " styleClass="grid_3 alpha" for="complementInputText" />
                        <p:inputText id="complementInputText" styleClass="grid_13" 
                                     value="#{managerProprietario.editarProprietario.endereco.compl}" />

                    </p:panel>
                    
                    <br/>
                    <br/>

                    <p:panel id="imoveisPanel"  
                             style="background: none; border: none; margin-left: -15px; margin-top: -25px;" 
                             styleClass="container_24 clearfix both" >

                        <p:dataTable id="tableImovel" var="item" value="#{managerProprietario.imoveis}" 
                                     styleClass="grid_24" rowIndexVar="rowid" 
                                     rowKey="#{item.id}" rows="5" paginator="true"  
                                     paginatorPosition="bottom" emptyMessage="Nenhum registro">  
                            <f:facet name="header">
                                <p:outputLabel value="Imóvel #{managerProprietario.imoveis eq null ? '' : '('.concat(managerProprietario.imoveis.size()).concat(')')}" />
                            </f:facet>
                            <p:column headerText="Ação" width="20" style="text-align: center">
                                <p:button  style="width: 20px; height: 20px;" 
                                           title="Editar"
                                           href="editarimovel.xhtml?eImovel=#{item.id}"
                                           icon="ui-icon-pencil"/>
                                <p:button  style="width: 20px; height: 20px;" 
                                           title="Visualizar"
                                           href="visualizarimovel.xhtml?vImovel=#{item.id}"
                                           icon="ui-icon-zoomin"/>

<!--                                <p:commandButton  style="width: 20px; height: 20px;" 
                                                  update="@form" title="Excluir"
                                                  oncomplete="dlg.show()"
                                                  icon="ui-icon-trash">
                                    <f:setPropertyActionListener target="{managerImovel.imovelDelete}" value="{item}" />
                                </p:commandButton>-->

                            </p:column>

                            <p:column headerText="Localização">  
                                <h:outputText value="Logradouro #{item.enderecoImovel.logradouro}, Nº #{item.enderecoImovel.numero}" />
                                <br/>
                            </p:column>
                            <p:column headerText="Bairro">  
                                <h:outputText value="#{item.enderecoImovel.bairro}"/>
                            </p:column>
                            <p:column headerText="Proprietário">  
                                <ui:repeat value="#{item.proprietarios}" var="o">
                                    <h:outputText value="#{o.nome}"/>
                                    <br/>
                                </ui:repeat>
                                <p:outputLabel style="color: red" value="Proprietário Pendente" 
                                               rendered="#{item.proprietarios.isEmpty()}" />
                            </p:column> 

                        </p:dataTable>

                    </p:panel>
                </p:panel>

                <br/>
                <div class="buttonAction">
                    <p:commandButton value="Salvar" icon="ui-icon-disk"
                                     update="@form"
                                     actionListener="#{managerProprietario.update()}"
                                     styleClass="ui-priority-primary" />

                    <p:button href="pesquisarproprietario.xhtml" value="Cancelar" icon="ui-icon-trash" />
                </div >
            </h:form>
        </ui:define>
    </ui:composition>

</html>
